package com.example.administrator.foodrowfresh.configs.classifyconfing.classifyadapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.administrator.foodrowfresh.R;
import com.example.administrator.foodrowfresh.configs.classifyconfing.classifyentity.MyClassifyLeftEntity;
import com.example.administrator.foodrowfresh.superBase.MyBaseAdapter;

import org.xutils.x;

import java.util.List;

/**
 * Created by lqr on 2016/5/2.
 */
public class MyLeftAdapter extends MyBaseAdapter<MyClassifyLeftEntity.DataBean.ListBean> {
    private List<MyClassifyLeftEntity.DataBean.ListBean> mList;
    private Context mContext;
    private int mPostion;
    public MyLeftAdapter(List<MyClassifyLeftEntity.DataBean.ListBean> list, Context mContext) {
        super(list, mContext);
        this.mList=list;
        this.mContext=mContext;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView==null){
            convertView= LayoutInflater.from(mContext).inflate(R.layout.layout_classify_left_item,parent,false);
            holder=new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }

        //给条目赋值
        holder.left_text.setText(mList.get(position).getName());


        //获取图片的路径：
        String image = mList.get(position).getImage();
        //下载图片
        x.image().bind(holder.left_imageView, image);
        holder.left_LinearLayout.setBackgroundColor(0xf7f4f5);
        if(position==mPostion){
            holder.left_LinearLayout.setBackgroundColor(Color.WHITE);
        }

        return convertView;
    }

    public class ViewHolder{
        TextView left_text;
        ImageView left_imageView;
        LinearLayout left_LinearLayout;
        public ViewHolder(View view) {
            left_text= (TextView) view.findViewById(R.id.classify_left_text);
            left_imageView= (ImageView) view.findViewById(R.id.classify_left_image);
            left_LinearLayout= (LinearLayout) view.findViewById(R.id.left_lagyout);
        }
    }

    public void getChange(int position){
        mPostion=position;
    }
}
